package com.shop.controller;


import com.github.pagehelper.Page;
import com.shop.domain.Task;
import com.shop.entity.PageResult;
import com.shop.entity.Result;
import com.shop.entity.StatusCode;
import com.shop.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/Task")
/**
 *  task
 */
public class TaskController {
    @Autowired
    private TaskService taskService;

    /**
     * 查询全部
     * @return
     */
    @GetMapping("/selectAll")
    public Result selectAll(){
        taskService.selectAll();
        return Result.ok("查询成功");
    }

    /**
     *条件查询
     * @param task
     * @return
     */
    @PostMapping("/selectList")
    public Result selectList(@RequestBody Task task){
        taskService.selectList(task);
        return Result.ok("条件查询成功");
    }

    /**
     *新增
     * @param task
     * @return
     */
    @PostMapping("/insert")
    public Result insert(@RequestBody Task task){
        taskService.insert(task);
        return Result.ok("新增成功");
    }

    /**
     * 删除
     * @param ids
     * @return
     */
    @GetMapping("/delete")
    public Result delete(@RequestParam String ids){
        taskService.delete(ids);
        return Result.ok("删除成功");
    }

    /**
     * 修改
     * @param task
     * @return
     */
    @PostMapping("/update")
    public Result update(@RequestBody Task task){
        taskService.update(task);
        return Result.ok("修改成功");
    }

    /**
     * 分页
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/pageAll")
    public Result pageAll(@RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "10") Integer size){
        Page<Task> taskPage = taskService.pageAll(page,size);
        PageResult pageResult = new PageResult(taskPage.getTotal(),taskPage.getResult());
        return Result.ok("查询成功",pageResult);
    }

    /**
     * 分页条件搜素
     * @param task
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/pageList")
    public Result pageList(@RequestBody Task task, @RequestParam(defaultValue = "1") Integer page,
                           @RequestParam(defaultValue = "10") Integer size){
        Page<Task> pageList = taskService.pageList(task,page,size);
        PageResult pageResult = new PageResult(pageList.getTotal(), pageList.getResult());
        return new Result(true, StatusCode.OK,"查询成功",pageResult);
    }
}
